<template>
	<view class="load" v-if="!load">
		<u-loading-icon mode="circle" inactive-color="#fff" text="正在加载..." vertical></u-loading-icon>
	</view>
	<view class="friends" v-else>
			<view class="list wap" v-if="Array.isArray(msglist) && msglist.length > 0">
				<view class="row item" v-for="(item,index) in msglist" :key="item.ID">
					<view class="col_4 ">
						<view class="cover">
							<view class="red" v-if="item.IsRead == 0"></view>
							<view v-if="item.FromUserID==0">
								<!-- <image src="https://golfdate.oss-cn-shenzhen.aliyuncs.com/img/icon_tz@2x.png" mode="aspectFill" /> -->
								通 知
							</view>
							<block v-else>
								<image :src="item.FromUserImgUrl" @click="tapHead(item,index)"
									mode="aspectFill" />
							</block>
						</view>
					</view>
					<view class="col_19" @click="toDetail(item,index)">
						<view class="hd">
							<view class="title f1 c1">{{ $util.entitiesToUtf16(item.Title) }}</view>
							<view class="time f3">{{ getTime(item.CreateTime) }}</view>
						</view>
						<view class="ft f2 c2">{{ $util.entitiesToUtf16(item.Content) }}</view>
					</view>
				</view>
			</view>
			<view v-else>
				<u-empty mode="list" width="100" height="100"
					icon="https://wavestation.oss-cn-shenzhen.aliyuncs.com/upload/1720073678914285.png" :show="true" iconSize="32"
					text="暂无消息"></u-empty>
			</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				load: false,
				list: [],
				_freshing: true,
				msglist: [],
				PageIndex: 1,
				readList: [],
				xtNum: 0,
				isMore: true,
			};
		},
		async onShow() {
		},
		onLoad() {
			this.getMsgList()
		},
		onReachBottom() {
			if (this.isMore) {
				this.PageIndex++;
				this.getMsgList();
			}
		},
		methods: {
			tapHead(e,index){
				if(e.IsRead==0) this.setRead(e.ID,index);
				this.nav_to(`/pages/user/user_visitor?id=${e.FromUserID}`)
			},
			toDetail(e,index) {
				if(e.IsRead==0) this.setRead(e.ID,index);
				if (e.Page_Url == '/pages/ball/ball_user_details' && e.Url_Pars.indexOf('type=my') != -1) {
					e.Page_Url = '/pages/ball/ball_details_prebook';
				}else if(e.Url_Pars == ''){
					this.tapHead(e,index)
				}
				let u = `${e.Page_Url}?${e.Url_Pars}`;

				this.nav_to(u);
			},
			//下拉刷新
			async onRefresh() {
				this.freshLoad = true;
				this.getMsgList()
			},
			
			async getMsgList() {
				let res = await this.$api.post('/MessageBox/MyMessage', {
					PageIndex: this.PageIndex,
					PageSize: 50
				});
				if (res.code == 0) {
					this.msglist = this.PageIndex == 1 ? this.msglist = res.data : this.msglist.concat(res.data)
				}
				this.xtNum = res.data.length;
				setTimeout(() => {
					this.load = true;
				}, 1000);

				this.isMore = Array.isArray(res.data) && res.data.length >= this.PageSize;

				return true;
			},
			async setRead(id,index) {
				let res = await this.$api.post('/MessageBox/Read', { ID: id });
				const {code} = res
				if (code == 0) {
					this.msglist[index].IsRead = 1
				}
			}
		}
	};
</script>

<style lang="scss">
	.friends {
		/deep/ .uni-list-chat {
			background: #111;
		}

		/deep/ .uni-list--border-top {
			background: #333;
		}

		/deep/ .uni-list--border-top {
			background: #333;
		}

		/deep/ .uni-list-chat__content-title {
			color: #fff;
		}

		/deep/ .uni-list-chat__content-note {
			color: #eee;
		}

		/deep/ .uni-list-chat__header-image {
			border-radius: 50%;
		}

		/deep/ .uni-list-chat__header {
			border: none;
		}
	}

	.item {
		position: relative;
		height: 150rpx;
		align-items: center;
		// border-bottom: 1px solid #fff;
	}

	.cover {
		position: relative;
		height: 100rpx;
		width: 100rpx;
		background: #444;
		border-radius: 50rpx;
		display: flex;
		align-items: center;
		justify-content: center;

		image {
			height: 100%;
			width: 100%;
			border-radius: 50%;
		}

		.red {
			display: flex;
			height: 20rpx;
			width: 20rpx;
			background: #fc4b65;
			position: absolute;
			top: 5rpx;
			right: 5rpx;
			border-radius: 200rpx;
		}
	}

	.hd {
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
	}

	.ft {
		margin-top: 10rpx;
	}

	.nav {
		height: 44px;

		.nav_left {
			margin-top: 7px;
			height: 30px;
			line-height: 30px;
			font-size: 32rpx;
			color: #fff;
			width: 200rpx;
			display: flex;
			align-items: center;

			// justify-content: center;
			text {
				padding-left: 10rpx;
				font-size: 32rpx;
				color: #fff;
				font-weight: bold;
			}
		}
	}
	.c1{
		color: #333;
	}
	.c2{
		color: #999;
	}
</style>